<template>
    <a-modal :visible="visible" :footer="null"
             :width="800"
             @cancel="handleCancel">
        <div>
            <a-table
                    ref="table"
                    bordered
                    size="middle"
                    rowKey="name"
                    :columns="columns"
                    :dataSource="dataSource"
                    :loading="loading">

            </a-table>
        </div>
    </a-modal>

</template>

<script>
import { postAction } from "@/api/manage";
export default {
  name: "TableModal",
  data() {
    return {
      visible: false,
      record: '',
      columns: [
        { title: '列名', align: "center", dataIndex: 'name', width: 120 },
        { title: '类型', align: "center", dataIndex: 'type', width: 120 },
        { title: '注释', align: "center", dataIndex: 'comment', width: 120 },
        { title: '精度', align: "center", dataIndex: 'precision', width: 120 },
        { title: '范围', align: "center", dataIndex: 'scale', width: 120 },
        { title: '长度', align: "center", dataIndex: 'maxLength', width: 120 },
        { title: '非空', align: "center", dataIndex: 'nullable', width: 120 }
      ],
      dataSource: [],
      loading: false,
      url: {
        baseUrl: 'codeGenerator/codeGenerator/schema/'
      }
    }
  },
  methods: {
    showTableColumn(record) {
      this.record = record
      this.visible = true
      this.$nextTick(() => {
        this.loadData()
      })
    },
    handleCancel() {
      this.visible = false
    },
    loadData() {
      if (this.record) {
        postAction(this.url.baseUrl + 'queryColumns', { tableName: this.record.name },'application/x-www-form-urlencoded').then((res) => {
          if (res.success) {
            this.dataSource = res.data;
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
